﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;

namespace FigureDraw.Graphic
{
    class GDIPlusSVGGraphic : CommonGraphic
    {
        string filename;
        StringBuilder svgContent;
        public GDIPlusSVGGraphic(string filename)
        {
            this.filename = filename;

            svgContent = new StringBuilder();
            svgContent.AppendLine("<svg xmlns=\"http://www.w3.org/2000/svg\" version=\"1.1\"></svg>");
        }

        override public void DrawLine(double x1, double y1, double x2, double y2)
        {
            svgContent.Insert(svgContent.Length - 8,
                string.Format("<line x1=\"{0}\" y1=\"{1}\" x2=\"{2}\" y2=\"{3}\" style=\"stroke-width:1;stroke:rgb(0,0,0)\" />", x1, y1, x2, y2));
            File.WriteAllText(filename, svgContent.ToString());
        }

        override public void DrawRectangle(double x, double y, double width, double height)
        {
            svgContent.Insert(svgContent.Length - 8,
                string.Format("<rect x=\"{0}\" y=\"{1}\" width=\"{2}\" height=\"{3}\" style=\"fill-opacity:0;stroke-width:1;stroke:rgb(0,0,0)\"/>", x, y, width, height));
            File.WriteAllText(filename, svgContent.ToString());
        }

        override public void DrawEllipse(double x, double y, double width, double height)
        {
            svgContent.Insert(svgContent.Length - 8,
                string.Format("<ellipse cx=\"{0}\" cy=\"{1}\" rx=\"{2}\" ry=\"{3}\" style=\"fill-opacity:0;stroke-width:1;stroke:rgb(0,0,0)\"/>", x + width / 2, y + height / 2, width / 2, height / 2));
            File.WriteAllText(filename, svgContent.ToString());
        }


        override public void DrawPicture(List<MyShape> shapes)
        {
            base.DrawPicture(shapes);
            File.WriteAllText(filename, svgContent.ToString());
        }

        public override void DrawText(string text, double size, double x, double y)
        {
            throw new NotImplementedException();
        }

        public override void DrawArc(double x, double y, double width, double height, double startAngle, double sweepAngle)
        {
            throw new NotImplementedException();
        }
    }
}
